|
|
Nicolas George <nicolas$george@salle-s.org> wrote:
> Warp wrote in message <44f1fe00@news.povray.org>:
> > Nicolas George <nicolas$george@salle-s.org> wrote:
> >> for(i = 0; i <= N; i++)
> >> r += (double)i * (i / 100000000);
> >
> > What is the type of 'i' there?
> An unsigned; but it should not change anything
Well, I asked because I suspected it was an integer, in which case
the above code doesn't make too much sense.
In C (and C++) the sentence "(i / 100000000)" is 0 for any (unsigned)
value of i less than 100000000. That because both arguments being integer,
that's an integer division, not a floating point one.
Then, of course, the first 'i' is multiplied by 0, so 'r' is repeatedly
added '0' to it, which makes no difference.
I don't know if this makes a difference in speed in different processors,
but it *might* be that the AMD64 can smartly perform those operations
(which always yield '0' as the answer) faster with its 64-bit-mode
enhancements. But not necessarily. It's just a guess.
Anyways, what you probably wanted to do is this:
r += (double)i * (i / 100000000.0);
which makes much more sense. Could you test if it that also is considerably
faster in 64-bit mode?
> register double r = 0; /* or not register */
The 'register' keyword is a no-op. It doesn't do anything and is just
a useless backwards-compatible drag of history.
(Besides, even when it meant something (like 20 years ago or so), you
couldn't possibly use it with a 'double' because registers are used for
integers only.)
--
- Warp
Post a reply to this message
|
|